# Contributor: wener <wenermail@gmail.com>
# Maintainer: wener <wenermail@gmail.com>
pkgname=thanos
pkgver=0.31.0
pkgrel=3
pkgdesc="Highly available Prometheus setup with long term storage capabilities. CNCF Sandbox project."
url="https://github.com/thanos-io/thanos"
license="Apache-2.0"
# prometheus
# 32-bit: doesn't build
arch="all !x86 !armhf !armv7 !riscv64"
install="thanos.pre-install"
makedepends="go prometheus tzdata"
subpackages="$pkgname-openrc"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/thanos-io/thanos/archive/v$pkgver.tar.gz
	assume-no-moving-gc.patch
	thanos.initd
	thanos.confd
	"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	GOLDFLAGS="
		-X github.com/prometheus/common/version.Version=$pkgver
		-X github.com/prometheus/common/version.Revision=AlpineLinux
		-X github.com/prometheus/common/version.Branch=master
		-X github.com/prometheus/common/version.BuildUser=build@xyz
		-X github.com/prometheus/common/version.BuildDate=$(date -u "+%Y%m%d-%H:%M:%S" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})
	"

	go build \
		-ldflags "$GOLDFLAGS" \
		./cmd/thanos
}

check() {
	# some tests need external storage credentials or running server
	# pkg/cacheutil go 1.15 compact
	# pkg/pool alloc too much memory
	# shellcheck disable=2046
	go test $(go list ./... | grep -v \
		-e 'test/e2e' \
		-e 'pkg/shipper' \
		-e 'pkg/store' \
		-e 'objstore/objtesting' \
		-e 'pkg/promclient' \
		-e 'pkg/rules' \
		-e 'pkg/compact' \
		-e 'pkg/block' \
		-e 'pkg/query' \
		-e 'pkg/cacheutil' \
		-e 'pkg/pool' \
		-e 'pkg/targets' \
		-e 'pkg/metadata' \
		)
}

package() {
	install -Dm755 thanos "$pkgdir"/usr/bin/thanos

	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
4bf4a0e3414c8157ca2ff1ae58c5e9c64d4966ac455495b95ccaa5bac2c726866e32cb30b8c87f2374f71b9eef27b6f8f05a578b69cabc535dd5cb806cb0a188  thanos-0.31.0.tar.gz
bc9fe59136862b04c10a8e091ff90e9dcd08680a6debddc5321b0bf30efe5cc043f6c7a97c2422f6ee9eb6e19ad7288e4af85115689c62f96413e0e8b99ee5ab  assume-no-moving-gc.patch
8407adbc29d90d36550ad16555d0b881d1d1745fba7bf5f4bd4a66bdf4abe196321106881dbba569c7e123d6abfbe78714b6e108b1e3c69b051270c3a46ba5c8  thanos.initd
c1bc9d71828b176eed964d5f673ea5e5d368f25ca21a3b12dcb8f8987f8bf12f35c06849d7fc4e6ffae52d98a5e636bdb63333930fe640c48e4d02a0b8db620a  thanos.confd
"
